//
//  ZRCellRetweet.swift
//  Sina
//
//  Created by 张锐 on 16/3/2.
//  Copyright © 2016年 zhangr. All rights reserved.
//

import UIKit
import SnapKit
class ZRCellRetweet: UIView {
    
    var constraint : Constraint?
    
    var statusViewModel : ZRHomeCellViewModel?{
    
        didSet{
        
        contentLabel.text = statusViewModel?.statusModel?.retweeted_status?.text
            
            constraint?.uninstall()
            
            if let pic_count = statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count where pic_count > 0{
            
                picImageView.hidden = false
                
                snp_updateConstraints { (make) -> Void in
                    
                    constraint = make.bottom.equalTo(picImageView.snp_bottom).constraint
                }
                //传值
                let picSatausViewModel = ZRHomeCellViewModel()
                picSatausViewModel.statusModel = statusViewModel?.statusModel?.retweeted_status
                
                picImageView.picViewModel = picSatausViewModel
                
            }else{
            
            
                picImageView.hidden = true
                
                snp_updateConstraints(closure: { (make) -> Void in
                    
                    constraint = make.bottom.equalTo(contentLabel.snp_bottom).constraint
                    
                })
            
            
            }
        
        }
    
    
    }

    //重写构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 245/255.0, alpha: 0.8)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //私有方法添加控件设置属性
    
    private func setupUI(){
    
        addSubview(contentLabel)
        addSubview(picImageView)
        
        //设置约束
        
        contentLabel.snp_makeConstraints { (make) -> Void in
           
            make.top.equalTo(self.snp_top)
            
            make.left.equalTo(self.snp_left).offset(10)
            
            make.right.equalTo(self.snp_right).offset(-10)
            
//            make.bottom.equalTo(self.snp_bottom)
        }
        
        picImageView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom)
            
            make.left.equalTo(self.snp_left).offset(10)
            
//            make.size.equalTo(CGSizeMake(100, 100))
        }
        
        snp_makeConstraints { (make) -> Void in
            
          constraint = make.bottom.equalTo(picImageView.snp_bottom).constraint
        }
        
    
    }
    //懒加载控件
    private lazy var contentLabel : UILabel = {
    
        let contentLabel = UILabel()
        
        contentLabel.text = "转发微博"
        
        contentLabel.textColor = UIColor.darkGrayColor()
        
        contentLabel.font = UIFont.systemFontOfSize(14)
        
        contentLabel.numberOfLines = 0
        
        return contentLabel
    
    }()
    
    private lazy var picImageView : ZRCellPic = ZRCellPic()
    

}
